class RadgroupchecksController < ApplicationController
  before_action :set_radgroupcheck, only: [:show, :edit, :update, :destroy]
  before_action :set_group, only: [:index, :new, :create, :edit]

  # GET /radgroupchecks
  # GET /radgroupchecks.json
  def index
    @radgroupchecks = Radgroupcheck.all
  end

  # GET /radgroupchecks/1
  # GET /radgroupchecks/1.json
  def show
    @group_id = params[:group_id]
  end

  # GET /radgroupchecks/new
  def new
    @radgroupcheck = @group.radgroupchecks.new
  end

  # GET /radgroupchecks/1/edit
  def edit
  end

  # POST /radgroupchecks
  # POST /radgroupchecks.json
  def create
    @radgroupcheck = @group.radgroupchecks.new(radgroupcheck_params)
    @radgroupcheck.groupname = @group.name

    respond_to do |format|
      if @radgroupcheck.save
        format.html { redirect_to [@group, @radgroupcheck], notice: 'Radgroupcheck was successfully created.' }
        format.json { render action: 'show', status: :created, location: @radgroupcheck }
      else
        format.html { render action: 'new' }
        format.json { render json: @radgroupcheck.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /radgroupchecks/1
  # PATCH/PUT /radgroupchecks/1.json
  def update
    respond_to do |format|
      if @radgroupcheck.update(radgroupcheck_params)
        format.html { redirect_to group_radgroupcheck_path(params[:group_id], @radgroupcheck), notice: 'Radgroupcheck was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @radgroupcheck.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /radgroupchecks/1
  # DELETE /radgroupchecks/1.json
  def destroy
    @radgroupcheck.destroy
    respond_to do |format|
      format.html { redirect_to group_radgroupchecks_url(params[:group_id]) }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_radgroupcheck
      @radgroupcheck = Radgroupcheck.find(params[:id])
    end

    def set_group
      @group = Group.find(params[:group_id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def radgroupcheck_params
      params.require(:radgroupcheck).permit(:attr, :op, :value)
    end
end
